<template>
  <div style="position: relative;">
    <el-row>
      <el-col span="3" :offset="3" id="str">
        新密码：
      </el-col>
      <el-col span="12">
        <el-input v-model="password" placeholder="请输入内容" ></el-input>
      </el-col>
    </el-row>
    <br />
    <el-row>
      <el-col span="3" style="position: absolute;left: 374px;">
        <el-input v-model="code" placeholder="请输入内容" class="code"></el-input>
         <el-button type="primary" @click="sendcode()" id="getCode" style="position: absolute;left: 255px;">获取验证码</el-button>
      </el-col>
    </el-row>
    <br />
    <el-button type="primary" @click="setPwd()" style="margin-top: 80px;margin-left: 650px;">修改</el-button>
    <div style="margin-left: 650px; margin-top: 140px;">
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <span>是否确认修改</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="setPassword()">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
 export default{
   name:"SetPassword",
   data(){
   	return{
      password:"",
      code:"",
      dialogVisible:false,
      accountPhone:JSON.parse(localStorage.getItem("user")).data.accountPhone
   	}
   },
   methods:{
      setPwd(){
        this.dialogVisible=true;
      },
      setPassword(){
        if(this.code==null || this.code == "" || this.password == null || this.password == ""){
          alert("验证码或密码不能空")
          this.dialogVisible=false;
        }else{
        this.$http.get("/account/setPassword",{
          	params:{
          		code:this.code,
              password:this.password
          	}
          }).then(resp=>{
          	if(resp.data.code == 200){
              this.dialogVisible=false;
              localStorage.setItem("user",JSON.stringify(resp.data))
              alert("修改成功")
              this.$router.push("/PersonalCenter")
            }
          })
        }
      },
      sendcode(){
        console.log(this.accountPhone)
        this.$http.get("/account/sendCode",{
          params:{
            phone:this.accountPhone
          }
        }).then(resp=>{
        	if(resp.data.code==200){
            alert("验证码已发送，请注意接收")
          }
        })
      }
   }
 }
</script>

<style>

</style>
